package com.zhuzhu.io;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriterUtil {

	private static String tempFileName;
	private static FileWriter fileWriter;
	
	public static FileWriter getFileWriter(String fileName) throws IOException{
		
		if (!fileName.equals(tempFileName)) {
			
		}
		
		if (fileWriter == null) {
			fileWriter = new FileWriter(new File(fileName),true);
			tempFileName = fileName;
		}
		return fileWriter;
	}
	
	public static void main(String[] args) {
		try {
			String fileName = "D:/a.txt";
			FileWriter  fileWriter = getFileWriter(fileName);
			fileWriter.write("abc\n");
			fileWriter.flush();
			fileWriter = getFileWriter("D:/b.txt");
			fileWriter.write("123\n");
			fileWriter.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
